//
//  ImportWalletInfoCell.m
//  ShandsMod
//
//  Created by zh s on 2023/3/21.
//  Copyright © 2023 zh_s. All rights reserved.
//

#import "ImportWalletInfoCell.h"

@implementation ImportWalletInfoCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.accessoryType = UITableViewCellAccessoryNone;
        self.backgroundColor = [UIColor clearColor];
        [self createView];
    }
    return self;
}

- (void)createView {
    
    NSArray *titleArr = @[@"钱包名称",@"设置密码",@"再次输入",@"密码提示"];
    NSArray *placeholderArr = @[@"设置钱包名称（以太坊）",@"请输入密码",@"请再次输入密码",@"非必填"];
    for (int i = 0; i <titleArr.count; i ++) {
        UIView *cellV = [[UIView alloc] init];
        [self.contentView addSubview:cellV];
//        cellV.backgroundColor = RandomColor;
        //cellV.frame = CGRectMake(31, CGRectGetMaxY(lineView.frame), SCREEN_WIDTH - 54, 60);
        [cellV mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(60 *i);
            make.left.mas_equalTo(31);
            make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH - 54, 60));
        }];
        
        UIView *cellLine = [[UIView alloc] init];
        [cellV addSubview:cellLine];
        cellLine.backgroundColor = LINEVIEWCELL_BACKCOLOR;
        [cellLine mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(0);
            make.bottom.mas_equalTo(cellV.mas_bottom);
            make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH - 54, 0.5));
        }];

        UILabel *titleLab = [BaseViewFactory labelWithFrame:CGRectZero textColor:RGB(20, 28, 48) font:FONT_NAME(FONT_Medium, 12) textAligment:NSTextAlignmentLeft andtext:titleArr[i]];
        [cellV addSubview:titleLab];
        [titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(7.5);
            make.bottom.mas_equalTo(cellV.mas_bottom).mas_offset(-18);
            make.height.mas_equalTo(15);
        }];

        UITextField *inputTF = [[UITextField alloc] init];
        [cellV addSubview:inputTF];
        inputTF.placeholder = placeholderArr[i];
        inputTF.textColor = MAIN_BACKCOLOR;
        inputTF.font = FONT_NAME(FONT_Medium, 12);

        inputTF.delegate = self;
        inputTF.tag = 100 +i;
        [inputTF mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(titleLab.mas_right).mas_offset(10);
            make.top.mas_equalTo(titleLab.mas_top).mas_offset(2);
            make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH - 80, 13));
        }];
        NSMutableAttributedString *placeholder = [[NSMutableAttributedString alloc] initWithString:placeholderArr[i]];
        NSString *placeholderStr = placeholderArr[i];

            [placeholder addAttribute:NSForegroundColorAttributeName

                                value:RGB(175, 182, 203)

                                range:NSMakeRange(0, placeholderStr.length)];

        inputTF.attributedPlaceholder = placeholder;
       
       
//        inputTF.keyboardType = UIKeyboardTypeNumberPad;

        UIImageView *iconImg = [[UIImageView alloc] init];
        [cellV addSubview:iconImg];
        iconImg.image = IMAGE_NAME(@"icon_tableview_star");
        [iconImg mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_equalTo(titleLab.mas_left).mas_offset(-2);
            make.centerY.mas_equalTo(titleLab.mas_centerY).mas_offset(-2);
            make.height.width.mas_equalTo(6);
        }];
        
        if ( i == 3) {
            iconImg.hidden = YES;
        }else if (i == 1) {
            UIButton *hidePassword = [BaseViewFactory buttonWithHeight:16 imagePath:@"icon_password_hide"];
            [cellV addSubview:hidePassword];
            [hidePassword mas_makeConstraints:^(MASConstraintMaker *make) {
                make.right.mas_equalTo(cellV.mas_right).mas_offset(-10);
                make.centerY.mas_equalTo(titleLab.mas_centerY);
                make.size.mas_equalTo(CGSizeMake(16, 16));
            }];
            [hidePassword addTarget:self action:@selector(hidePasswordClick:) forControlEvents:UIControlEventTouchUpInside];
        }
    }

}

- (void)hidePasswordClick:(UIButton *)sender {
    sender.selected = !sender.selected;
    UITextField *passwordTF = [self viewWithTag:101];
    passwordTF.secureTextEntry = sender.selected;
}
@end
